import hmac
import time
from hashlib import sha256

import requests


def get_sign(data, key):
    key = key.encode('utf-8')
    message = str(data).encode('utf-8')
    sign = hmac.new(key, message, digestmod=sha256).hexdigest().upper()
    return sign


def get_timestamp():
    return int(time.time() * 1000)


url = "https://fapi.binance.com/fapi/v1/order"

headers = {
    'X-MBX-APIKEY': 'tNpiu74NorF66Ihrj1e8C01C5T1JhudQNv1D01LH63hL7nwYtT8v2cJ71J7qqWcP',
}
secretKey = "vMhvTcBC0Z9rtQbonm5RqXtP6npNS7sVI92WhfMzZBBXKGNMm92dFNLUiQi29Y8G"
timestamp = str(get_timestamp())
params = {
    "timestamp": timestamp,
    "recvWindow": 10000000,
    "signature": get_sign("timestamp="+timestamp+"&recvWindow=10000000&symbol=ETCUSDT", secretKey)
}

res = requests.get(url=url, headers=headers, params=params)
print(res.json())
for data in res.json():
    print(data)
